package com.yulan.fastkillcourse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yulan.fastkillcourse.Dto.CourseDto;
import com.yulan.fastkillcourse.model.Course;
import com.yulan.fastkillcourse.service.CourseService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

@SpringBootTest
class testCourse {


    @Autowired
    CourseService courseService;



    @Test
    public void testCount(){
        System.out.println(courseService.count());
    }

    @Test
    public void testTime(){
        GregorianCalendar endTime = new GregorianCalendar();
        endTime.set(2020, Calendar.MARCH, 2,0,0,0);
        System.out.println(endTime.getTime());
    }

    @Test
    public void testInsert(){

        for(int i=0;i<10;i++){
            GregorianCalendar startTime = new GregorianCalendar();
            startTime.set(2020, Calendar.MARCH, 31,23,0,0);

            GregorianCalendar endTime = new GregorianCalendar();
            endTime.set(2020, Calendar.APRIL, 20,0,0,0);

            Course course = Course.builder()
                    .startTime(startTime.getTime())
                    .endTime(endTime.getTime())
                    .name("数据库系统与概念")
                    .teacherName("郭玉彬"+i)
                    .kind(1)
                    .introduction("数据库噢！！！")
                    .build();

            courseService.save(course);
        }
    }

    @Test
    public void testJson2COurse(){

        GregorianCalendar startTime = new GregorianCalendar();
        startTime.set(2020, Calendar.MARCH, 31,23,0,0);

        GregorianCalendar endTime = new GregorianCalendar();
        endTime.set(2020, Calendar.APRIL, 20,0,0,0);


        CourseDto courseDto = CourseDto.builder()
                .cid(44)
                .hot(100)
                .kind(1)
                .name("软件工程")
                .teacherName("朱凯10")
                .startTime(startTime.getTime())
                .endTime(endTime.getTime())
                .score(100)
                .timeInterval(1)
                .build();

        String jsonCourseDto = JSON.toJSONStringWithDateFormat(courseDto, "yyyy-MM-dd HH:mm:ss");
        System.out.println(jsonCourseDto);


    }

    @Test
    public void testGetAll(){
        for(Course course:courseService.list()){
            System.out.println(course);
        }
    }

    @Test
    public void testGetSome(){
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.inSql("cid","select cid from t_courses where score >= 99");
        for(Course course : courseService.list(queryWrapper)){
            System.out.println(course);
        }
    }
}
